<template>
  <el-dialog
    v-dialogDrag
    title="编辑"
    :visible="isShowEditDialog"
    width="40%"
    @close="dialogClose"
    :close-on-click-modal="false"
  >
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="auto">
      <el-form-item label="文档名称:" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>

      <el-form-item label="标准类型:" prop="type">
        <el-select
          v-model="ruleForm.type"
          placeholder="请选择"
          style="width: 100%"
        >
          <el-option
            v-for="item in DocumentTypeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="文档价格:" prop="price">
        <el-input v-model="ruleForm.price"></el-input>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogClose">取 消</el-button>
      <el-button type="primary" @click="submitForm()">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { updateDocument } from "@/api/systemManage/documentManage";
import { findByName } from "@/api/systemManage/dataDictionary";
export default {
  // 接受父组件
  props: {
    isShowEditDialog: {
      type: Boolean,
    },
    record: {
      type: Object,
    },
  },
  data() {
    return {
      fileList: [],
      DocumentTypeOptions: [],
      ruleForm: {
        name: "",
        type: "",
        price: "",
      },
      // 必填项
      rules: {
        name: [
          { required: true, message: "请输入文档名称", trigger: "change,blur" },
        ],
        type: [
          { required: true, message: "请选择标准类型", trigger: "change,blur" },
        ],
        price: [
          { required: true, message: "请输入文档价格", trigger: "change,blur" },
        ],
      },
    };
  },

  methods: {
    dialogClose() {
      this.$emit("dialogClose");
    },
    submitForm() {
      this.$refs.ruleForm.validate((valid) => {
        if (!valid) {
          return;
        } else {
          this.$delete(this.ruleForm, "createTime");
          this.ruleForm.companyID = 2;
          updateDocument(this.ruleForm).then((res) => {
            this.$emit("close");
            this.$emit("dialogClose");
          });
        }
      });
    },
    getType() {
      findByName("input=" + "标准类型").then((res) => {
        for (var i = 0; i < res.data.length; i++) {
          if(res.data[i].dictName=='标准类型')
          this.DocumentTypeOptions.push({
            label: res.data[i].dictValue,
            value: res.data[i].dictValue,
          });
        }
      });
    },
    handleExceed(file) {
      this.ruleForm.url = file.data;
    },
  },
  mounted() {
    this.ruleForm = Object.assign({}, this.record);
    this.getType();
  },
};
</script>

<style></style>
